package com.solute.web.sso.login.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.solute.domain.LoginVO;
import com.solute.domain.UserVO;
import com.solute.web.sessions.User;
import com.solute.web.sso.login.dao.LoginDao;

@Service
public class LoginService {
	
	private static final Logger logger = LoggerFactory.getLogger(LoginService.class);
	private @Autowired LoginDao dao;
	
	public boolean checkLogin(LoginVO param) {
		logger.info("Checked Login (user:{})", param.getEmail());
		return param.getPassword().equals(dao.getUserPassword(param.getEmail()));
	}
	
	@Transactional
	public void saveLogin(LoginVO loginVO, String ip) {
		UserVO userVO = new UserVO(loginVO.getEmail(), loginVO.getPassword(), ip);
		dao.updateUserIp(userVO);
	}
	
	public User getUserFromIp(String ip) {
		return dao.getUserFromIp(ip);
	}
}
